package com.study.securitydemo.controller;

import com.study.securitydemo.entity.User;
import com.study.securitydemo.service.IUserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author weiyongpeng
 * @ClassName: UserController
 * @Description: 用户Controller层
 * @date 2024/10/26
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource // 在SpringBoot3中，不在支持@AutoWare注入，如果要用需要配合@Quailfiar注解
    private IUserService userService;

    @GetMapping("/list")
    public List<User> findUserList(){
        return userService.list();
    }

    @PostMapping("/add")
    public String add(@RequestBody User user) {
        boolean save = userService.saveUserDetails(user);
        return save ? "添加成功" : "添加失败";
    }
}